using System.CodeDom;
using CodeDomHelper.Types;
using System;
using System.Diagnostics;

namespace CodeDomHelper.CodeDom
{

    [DebuggerDisplay("{TypeExpression}", Name = "CdeType")]
    [Serializable()]
    [System.Diagnostics.DebuggerStepThrough()]
    public partial class TypeExp : CodeTypeReference
    {


        #region Ctor
        
        public TypeExp(TypeExpression type)
            : this(type.AssemblyQualifiedName)
        {

        }

        public TypeExp(TypeExpression type, CodeTypeReferenceOptions option)
            : this(type.AssemblyQualifiedName, option)
        {

        }

        public TypeExp(TypeExp type)
            : this(type.TypeExpression)
        {

        }

        public TypeExp(TypeExp type, CodeTypeReferenceOptions option)
            : this(type.TypeExpression, option)
        {
            TypeExpression = type.TypeExpression.Clone();
        }

        public TypeExp(Type type)
            : base(type)
        {
            try
            {

                string txt = type.AssemblyQualifiedName;
                TypeExpression = BuildTypeExpression.Analyse(txt);

            }
            catch (Exception)
            {
                
                throw;
            }
            
        }

        public TypeExp(Type type, CodeTypeReferenceOptions option)
            : base(type, option)
        {
            TypeExpression = BuildTypeExpression.Analyse(type.AssemblyQualifiedName);
        }

        public TypeExp(string type)
            : base(type)
        {
            TypeExpression = BuildTypeExpression.Analyse(type);
        }

        public TypeExp(string type, CodeTypeReferenceOptions option)
            : base(type, option)
        {
            TypeExpression = BuildTypeExpression.Analyse(type);
        }

        #endregion


        public TypeExpression TypeExpression { get; private set; }

        public CodeTypeReferenceExpression ReferenceExpression { get { return new CodeTypeReferenceExpression(this); } }

        public CodeTypeOfExpression TypeOf { get { return new CodeTypeOfExpression(this); } }

        public static Type Object { get { return typeof(Object); } }

        public static TypeExp Void { get { return null; } }

        public CodeObjectCreateExpression New(params CodeExpression[] parameters) { return new CodeObjectCreateExpression(this, parameters); }

        public static CodeExpression Null { get { return new CodePrimitiveExpression(null); } }

        public CodeDefaultValueExpression DefaultValue { get { return new CodeDefaultValueExpression(this); } }


    }

}
